package me.firstapp.manage.category;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import me.firstapp.common.json.SingleObject;
import me.firstapp.common.module.shop.JsonCategory;
import me.firstapp.manage.common.BaseManage;
import me.firstapp.spi.shop.CategoryService;

@Controller
@RequestMapping(value = "/categoryManage")
public class CategoryManagePage extends BaseManage {

	@Autowired
	private CategoryService categoryService;

	@RequestMapping(value = "/categoryList.html", method = RequestMethod.GET)
	public ModelAndView categoryListView(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		return new ModelAndView("category/categoryList", modelMap);
	}

	@RequestMapping(value = "/categoryUpdate.html", method = RequestMethod.GET)
	public ModelAndView categoryUpdateView(Long categoryId, HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {
		SingleObject<JsonCategory> singleObject = categoryService.findCategoryById(categoryId);
		modelMap.put("category", singleObject.getObject());
		modelMap.put("categoryId", categoryId);
		return new ModelAndView("category/categoryUpdate", modelMap);
	}

	@RequestMapping(value = "/categoryAdd.html", method = RequestMethod.GET)
	public ModelAndView categoryAddView(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		return new ModelAndView("category/categoryAdd", modelMap);
	}
}
